﻿#define _CRT_SECURE_NO_WARNINGS
#include"unordered_map.h"
#include"unordered_set.h"

namespace sj
{
	void Print(const unordered_set<int>& s)
	{
		unordered_set<int>::const_iterator it = s.begin();
		while (it != s.end())
		{
			// *it = 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}
	void test_set()
	{
		unordered_set<int> s;
		s.insert(4);
		s.insert(14);
		s.insert(2);
		s.insert(12);
		s.insert(2);
		s.insert(222);
		s.insert(21);

		unordered_set<int>::iterator it = s.begin();
		// ֤key޸
		// *it += 100;
		while (it != s.end())
		{
			cout << *it << " ";
			++it;
		}
		cout << endl;

		Print(s);
	}
	void test_map()
	{
		unordered_map<string, string> m;
		m.insert({ "sort", "1" });
		m.insert({ "left", "2" });

		m.insert({ "right", "3" });
		// 
		m["insert"];
		for (auto& e : m)
		{
			// e.first += 'x';
			//e.second += 'x';

			cout << e.first << ":" << e.second << endl;
		}
		cout << endl;

		// ޸
		m["insert"] = "";
		for (auto& e : m)
		{
			// e.first += 'x';
			//e.second += 'x';

			cout << e.first << ":" << e.second << endl;
		}
		cout << endl;

		// +޸
		m["string"] = "ַ";
		for (auto& e : m)
		{
			// e.first += 'x';
			//e.second += 'x';

			cout << e.first << ":" << e.second << endl;
		}
		cout << endl;

		string arr[] = { "ƻ", "", "ƻ", "", "ƻ", "ƻ", "","ƻ", "㽶", "ƻ", "㽶" };
		unordered_map<string, int> countMap;
		for (auto& str : arr)
		{
			countMap[str]++;
		}

		for (auto& e : countMap)
		{
			cout << e.first << ":" << e.second << endl;
		}
		cout << endl;
	}
}


int main()
{
	sj::test_set();
	sj::test_map();
	return 0;
}